package com.leji.song.mainPage;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import com.baidu.mapapi.map.*;
import com.baidu.mapapi.model.LatLng;
import com.leji.song.R;
import com.leji.song.extra.BaseActivity;

///**
// * Created by colin.ding on 2014/7/1.
// */
//public class MapActivity extends BaseActivity{
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        setAnimType(RIGHT_ENTER_LEFT_EXT);
//        super.onCreate(savedInstanceState);
//
//        setContentView(R.layout.baidu_map);
//    }
//}

public class MapActivity extends BaseActivity {
    @SuppressWarnings("unused")
    private static final String LTAG = MapActivity.class.getSimpleName();
    private MapView mMapView;
    private BaiduMap mBaiduMap;
    private LinearLayout map_View_layout;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        setAnimType(RIGHT_ENTER_LEFT_EXT);
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        if (intent.hasExtra("x") && intent.hasExtra("y")) {
            // 当用intent参数时，设置中心点为指定点
            Bundle b = intent.getExtras();
            LatLng p = new LatLng(b.getDouble("y"), b.getDouble("x"));
            mMapView = new MapView(this,
                    new BaiduMapOptions().mapStatus(new MapStatus.Builder()
                            .target(p).zoom(15.0f).build()));

            mBaiduMap = mMapView.getMap();
            //构建Marker图标
            BitmapDescriptor bitmap = BitmapDescriptorFactory
                    .fromResource(R.drawable.location2);
//构建MarkerOption，用于在地图上添加Marker
            OverlayOptions option = new MarkerOptions()
                    .position(p)
                    .icon(bitmap);
//在地图上添加Marker，并显示
            mBaiduMap.addOverlay(option);

        } else {
            mMapView = new MapView(this, new BaiduMapOptions());
            mBaiduMap = mMapView.getMap();
        }

        setContentView(R.layout.baidu_map);

        map_View_layout = (LinearLayout)findViewById(R.id.map_View_layout);
        map_View_layout.addView(mMapView);

        initView();
    }

    private void initView() {
        setReturnBtn();
        setActivityTitle("店家地址");
    }

    @Override
    protected void onPause() {
        super.onPause();
        // activity 暂停时同时暂停地图控件
        mMapView.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        // activity 恢复时同时恢复地图控件
        mMapView.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // activity 销毁时同时销毁地图控件
        mMapView.onDestroy();
    }

}
